﻿@using DTcms.Common;
@{
    ViewBag.Title = "扩展字段管理";
    List<SelectListItem> list = new List<SelectListItem>(){
        new SelectListItem(){Text="所有类型", Value=""},
        new SelectListItem(){Text="单行文本", Value="single-text"},
        new SelectListItem(){Text="多行文本", Value="multi-text"},
        new SelectListItem(){Text="编辑器",Value="editor"},
        new SelectListItem(){Text="图片上传",Value="images"},
        new SelectListItem(){Text="视频上传",Value="video"},
        new SelectListItem(){Text="数字",Value="number"},
        new SelectListItem(){Text="时间日期",Value="datetime"},
        new SelectListItem(){Text="复选框",Value="checkbox"},
        new SelectListItem(){Text="多项单选",Value="multi-radio"},
        new SelectListItem(){Text="多项多选",Value="multi-checkbox"},
        new SelectListItem(){Text="同类选择",Value="similar"}
    };
}
<div class="pageheader">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
            <li><a href="javascript:;">扩展字段管理</a> </li>
        </ul>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card layui-tab">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="menu-list">
                        <div class="layui-inline">
                            <div class="layui-input-inline mr0">
                                <input id="txtKeywords" class="layui-input" type="text" placeholder="输入关键字" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" id="btnSearchAuth" data-type="btnSearch">
                                <i class="layui-icon">&#xe615;</i>搜索
                            </button>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-btn-group">
                            <a data-type="btnAdd" class="layui-btn icon-btn layui-btn-normal layui-btn-sm" href="../channel/attribute_field_edit?action=@DTEnums.ActionEnum.Add"><i class="iconfont icon-close1"></i> 新增</a>
                            <a data-type="btnDelete" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="iconfont icon-delete"></i> 删除</a>
                        </div>
                        <div class="menu-select">
                            @Html.DropDownList("ddlControlType", new SelectList(list, "Value", "Text"), new { @lay_filter = "btnSearch" })
                        </div>
                    </div>
                </div>
            </div>
            <table class="layui-table" lay-data="{page:true, id:'ltable'}" lay-filter="ltable">
                <thead>
                    <tr>
                        <th lay-data="{checkbox:true}"></th>
                        <th lay-data="{field:'name'}">列名</th>
                        <th lay-data="{field:'title'}">标题</th>
                        <th lay-data="{field:'control_type',templet:'#type'}">类型</th>
                        <th lay-data="{field:'is_required',templet:'#is_required'}">必填</th>
                        <th lay-data="{field:'is_sys',templet:'#is_sys'}">系统默认</th>
                        <th lay-data="{field:'sort_id',edit: 'text'}">排序</th>
                        <th lay-data="{templet: '#barDemo'}">操作</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<script type="text/html" id="type">
    {{#
        switch (d.control_type) {
            case "single-text":
                return "单行文本";
                break;
            case "datetime":
                return "时间日期";
                break;
            case "multi-text":
                return "单行文本";
                break;
            case "editor":
                return "编辑器";
                break;
            case "images":
                return "图片上传";
                break;
            case "video":
                return "视频上传";
                break;
            case "number":
                return "数字";
                break;
            case "checkbox":
                return "复选框";
                break;
            case "multi-radio":
                return "多项单选";
                break;
            case "multi-checkbox":
                return "多项多选";
                break;
            case "similar":
                return "同类选择";
                break;
            default:
                return "未知类型";
                break;
        }
    }}
</script>
<script type="text/html" id="is_sys">
    {{d.is_sys==0?'<i class="simple text-success icon-close"></i>':'<i class="simple text-warning icon-check"></i>'}}
</script>
<script type="text/html" id="is_required">
    {{d.is_required==0?'<i class="simple text-success icon-close"></i>':'<i class="simple text-warning icon-check"></i>'}}
</script>
<script type="text/html" id="barDemo">
    <a href="../channel/attribute_field_edit?action=@DTEnums.ActionEnum.Edit&id={{d.id}}" class="layui-btn layui-btn-primary layui-btn-xs">修改</a>
</script>
<script type="text/html" id="nameTpl">
    <a href="../channel/attribute_field_edit?action=@DTEnums.ActionEnum.Edit&id={{d.id}}" class="layui-table-link">{{ d.name }}</a>
</script>
@section Scripts{
    <script type="text/javascript">
        layui.use(['table', 'cmswh'], function () {
            var table = layui.table, form = layui.form, cmswh = layui.cmswh, $ = layui.jquery;
            
            cmswh.dataBind('FiledList');
            //监听单元格编辑
            table.on('edit(ltable)', function (obj) {
                cmswh.request("AttributeFiledSave", "POST", { field: obj.field, value: obj.value, id: obj.data.id });
            });
            form.on('select(btnSearch)', function (data) {
                var type = "btnSearch";
                active[type] ? active[type].call(this) : '';
            });
            var active = {
                btnDelete: function () {
                    cmswh.batOperate('AttributeDelete', 'id');
                },
                btnSearch: function () {
                    table.reload('ltable', { page: { curr: 1 }, where: getcond() });
                }
            };
            $('.layui-inline .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            /*拼接条件返回postdata*/
            function getcond() {
                var keywords = $("#txtKeywords").val();
                var type = $("#ddlControlType").val();
                var postdata = { keywords: keywords, control_type: type };
                return postdata;
            }
        });
    </script>
}